﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VoiceAd.Models;
using VoiceAd.DAL;
using System.IO;
using System.Web.Security;
using System.Text;

namespace VoiceAd.Controllers
{
    public class ServicesController : Controller
    {
        //
        // GET: /Services/
        private IServicesRepository servicesRepository = new ServicesRepository(new dbVoiceAdDataContext());
        private IContentRepository contentRepository = new ContentRepository(new dbVoiceAdDataContext());
        public ActionResult Index(string name)
        {
            int id = int.Parse(name.Split('-').Last().Replace(".html", string.Empty).ToString());

            if (id == 1)
            {
                return RedirectToAction("loundspeak");
            }

            tblServices tbl = servicesRepository.GetServiceById(id);

            ViewBag.Id = tbl.Id;
            ViewBag.ServiceName = tbl.Title_Vn;
            ViewBag.Body = tbl.Body_Vn;

            subMenuServices();

            return View();
        }

        public ActionResult AboutUs()
        {
            tblContent tbl = contentRepository.GetListContent().FirstOrDefault();
            ViewBag.Id = tbl.Id;
            ViewBag.ServiceName = tbl.Title_VI;
            ViewBag.Body = tbl.Body_VI;
            subMenuServices();
            return View();
        }

        public void subMenuServices()
        {
            StringBuilder str = new StringBuilder();
            str = str.AppendLine("<ul class='sub-options'>");
            IEnumerable<tblServices> lstServices = servicesRepository.GetListService();
            foreach (tblServices tbl in lstServices)
            {
                string lUrl = Url.Content("~/service-" + VoiceAd.Common.UrlEncode.ToFriendlyUrl(tbl.Title_Vn) + "-" + tbl.Id.ToString() + ".html");
                str.AppendLine("<li><a href=" + lUrl + ">" + tbl.Title_Vn + "</a></li>");
            }
            str = str.AppendLine("</ul>");
            ViewBag.lstSubMenu = str.ToString();
        }

        public ActionResult loundspeak()
        {
            ViewBag.lstImage = Galery();
            subMenuServices();
            return View();
        }

        private SelectList Galery(object obj = null)
        {
            List<SelectListItem> items = new List<SelectListItem>();

            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/1.png", Value = "Trang 1" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/2.png", Value = "Trang 2" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/3.png", Value = "Trang 3" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/4.png", Value = "Trang 4" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/5.png", Value = "Trang 5" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/6.png", Value = "Trang 6" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/7.png", Value = "Trang 7" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/8.png", Value = "Trang 8" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/9.png", Value = "Trang 9" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/10.png", Value = "Trang 10" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/11.png", Value = "Trang 11" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/12.png", Value = "Trang 12" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/13.png", Value = "Trang 13" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/14.png", Value = "Trang 14" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/15.png", Value = "Trang 15" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/16.png", Value = "Trang 16" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/17.png", Value = "Trang 17" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/18.png", Value = "Trang 18" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/19.png", Value = "Trang 19" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/20.png", Value = "Trang 20" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/21.png", Value = "Trang 21" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/22.png", Value = "Trang 22" });
            items.Add(new SelectListItem { Text = "../Content/images/slide_loundspeak/23.png", Value = "Trang 23" });

            return new SelectList(items, "Value", "Text", obj);
        }
    }
}
